package com.threaddemo4;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;

public class ThenComposeDemo {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<String> f1 = CompletableFuture.supplyAsync(()->{
            System.out.println("F1 " + Thread.currentThread().getName());
            return "F1 返回值";
        });

        CompletableFuture<String> tc = f1.thenCompose(r->{
            System.out.println("执行 ThenCompose..." + Thread.currentThread().getName());
           return CompletableFuture.supplyAsync(()->{
               System.out.println("执行 ThenCompose 内部任务 " + Thread.currentThread().getName());
               return "thenCompose 返回值";
           });
        });

        System.out.println("f1 = " + f1.get());
        System.out.println("tc = " + tc.get());

    }
}
